package com.java.dormitorymanager.filter;

import com.java.dormitorymanager.pojo.Manager;

import javax.print.attribute.standard.MediaSize;
import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @program: DormitoryManager
 * @description: 登录过滤器
 * @author: ShuangChenYue
 * @create: 2021-05-19 09:52
 **/

//此过滤器由于最后添加，导致与之前的方法冲突，功能重叠，于是弃用。
/*@WebFilter(filterName = "LoginFilter",urlPatterns = {"/mvc/managerLogin.do"})
public class LoginFilter implements  Filter{
    private FilterConfig filterConfig;

    public FilterConfig getFilterConfig() {
        return filterConfig;
    }

    public void setFilterConfig(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        Manager manager = (Manager) request.getSession().getAttribute("filterManager");
        if(manager != null){
            //若返回的值不为空，再去干其他的事
            filterChain.doFilter(request,response);
        }else{
            request.getRequestDispatcher("http://localhost:8080/DormitoryManager/html/manager/login.html").forward(request,response);
        }

    }

    @Override
    public void destroy() {

    }
}*/
